/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2022-09-27
 * Time: 21:52
 */
public class Test1 {
   public static int removeDuplicates(int[] nums) {
       int l = 0;
       for (int i = 1; i < nums.length; i++) {
           if (nums[l] != nums[i]) {
               nums[++l] = nums[i];
           }
       }
       return l + 1;
   }
    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,5,6,6};
        int l = removeDuplicates(nums);
        for (int i = 0; i < l; i++) {
            System.out.println(nums[i]);
        }
    }
    public static void merge(int[] nums1,int m ,int[] nums2,int n){
        int tail = nums1.length - 1;
        int p1 = m - 1;
        int p2 = n - 1;
        while(p1 >= 0){
            if(p2 == -1||nums1[p1] >= nums2[p2]){
                nums1[tail--] = nums2[p1--];
            }else {
                nums1[tail--] = nums1[p2--];
            }
        }
    }

//    public static void merge(int[] nums1, int m, int[] nums2, int n) {
//        int[] sort = new int[m+n];
//        int p1 = 0;
//        int p2 = 0;
//        int cur = 0;
//        while (p1 < m || p2 < n) {
//            if (p1 == m) {
//                cur = nums2[p2++];
//            } else if (p2 == n) {
//                cur = nums1[p1++];
//            } else if (nums1[p1] > nums2[p2]) {
//                cur = nums2[p2++];
//            } else {
//                cur = nums1[p1++];
//            }
//            sort[p1 + p2 - 1] = cur;
//        }
//        for (int i = 0; i != m+n ; i++) {
//            nums1[i] = sort[i];
//        }
//    }
        public static void main1(String[] args) {
        int[] nums1 = {1,2,3,0,0,0};
        int[] nums2 = {1,2,3};
        int m = nums1.length;
        int n = nums2.length;
        m= m-n;
        merge(nums1,m,nums2,n);
            for (int x:nums1) {
                System.out.println(x);
            }

    }
}
